<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$THEME->addBreadcrumb($this->adminUrl, $this->lang('breadcrumb_browse'));


if(!class_exists('ZipArchive')){
	JFX::addError('Import/Export requires PHP ZipArchive extension');
}


if(Antz_IntelliForm::submitted('import')){
	$file = $_FILES['file'];
	if(file_exists($file['tmp_name'])){
		$export = new JFX_Module_Imager_Export;
		$export->import($file['tmp_name']);
		JFX::addSuccess('Imported OK');
	}
}








if(get('folder')!=''){
	// show the list of photos by ajax request

	$folderName = get('folder');
	$folderTitle = $this->getContentLang('folder_title', $folderName);
	$folderPath = $this->getFolderPath($folderName);
	$realRes = array();

	$res = JFX_Data::getModuleFilesByPrefix($this->keyname, $folderPath);

	$folder = new JFX_Module_Imager_Folder();
	

	foreach($res as $k=>$photo){
		$folder->addFile($photo);
	}

	$export = new JFX_Module_Imager_Export;
	$export->addFolder($folder);
	$export->compress($folderName, $folderTitle);
	$export->printFile($folderName.'_'.date('Y-m-d').'.zip');

}


$tree = $this->getFolderHeirarchy();

$folderUrl = $this->adminUrl.'/import-export/?folder=:|folder|:&redirect';
$click = '';

$formFields = array(
    array(
	'type' => 'file',
	'name' => 'file',
	'label' => 'File',
	'value' => ''
    ),
    array(
	'type' => 'submit',
	'label' => '&nbsp;',
	'value' => 'Import'
    )
);


// show the folder tree
echo '<div class="jfx-imager-folder-tree"><h2>Export</h2><h3>'.$this->lang('choose_a_folder').'</h3>';
echo '<ul id="JFX_Module_Imager_FolderTreeview" class="treeview" style="float: left">'.
$this->makeTree($tree, $this, false, $folderUrl, $folderUrl, $click, $click).'</ul></div>';

echo '<div style="clear:both;"></div>';

$script = <<<JS
<script type="text/javascript" language="JavaScript">

$('#JFX_Module_Imager_FolderTreeview').treeview({
			persist: "location",
			collapsed: true,
			unique: true
		});

function jfx_imager_edit_photo(filepath){
	var src = '{$CONFIG->baseUrl}/jfx/phpimageeditor/index.php?imagesrc='+filepath;
	$('#jfx-imager-phpeditor-iframe > iframe').attr('src', src);
}

$('#jfx-imager-phpeditor-iframe').resizable();

</script>
JS;

echo $script;

echo '<div class="jfx-imager-import">'.JFX::makeRapidForm($formFields, 'Upload a file', 'import').'</div>';


